package demo05;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-10
 * Time: 20:36
 */
public class Test06 {
    public static void main1(String[] args) {
        int b = 60, c = 0;
        try {
            if (c == 0) {
                //c为除数，可能会为0，所以请手动抛出ArithmeticException异常
                throw new ArithmeticException();
            }else {
                System.out.println(b + "/" + c + " = " + b/c);
            }
        }catch (ArithmeticException e) {
            //输出“除法时分母为0” 和 异常类e
            System.out.println("除法时分母为0" +" " +e);
        }
    }
    //方法m()抛出Exception异常，
    static void m() throws Exception {
        int a=3;
        int b=0;
        if(b==0) {
            throw new Exception();
        }
        int c=a/b;
        System.out.println(a+"/"+b+"="+c);
    }
    public static void main(String[] args) {
        try {
            m();
        } catch (Exception e) {
            System.out.println("捕获的异常：" + e);
        }
    }
}
